1
2
3
4
5
6 [hpp]#include <sngcm/cmparser/ParserApi.hpp>
7 [hpp]#include <sngcm/ast/GlobalVariable.hpp>
8 [hpp]#include <sngcm/cmparser/ParsingContext.hpp>
9 [cpp]#include <sngcm/cmparser/Specifier.hpp>
10 [cpp]#include <sngcm/cmparser/Identifier.hpp>
11 [cpp]#include <sngcm/cmparser/TypeExpr.hpp>
12 [cpp]#include <sngcm/cmparser/Expression.hpp>
13 [cpp]#include <sngcm/cmlexer/CmajorLexer.hpp>
14 [cpp]#include <sngcm/cmlexer/CmajorTokens.hpp>
15
16 using namespace sngcm::ast;
17 using namespace CmajorTokens;
18
19 parser api(SNGCM_PARSER_API) GlobalVariableParser
20 {
21 uselexer CmajorLexer;
22
23 using SpecifierParser.Specifiers;
24 using TypeExprParser.TypeExpr;
25 using IdentifierParser.Identifier;
26 using ExpressionParser.Expression;
27
28 GlobalVariable(boost::uuids::uuid* moduleId, ParsingContext* ctx, sngcm::ast::CompileUnitNode* cu, var Span s) : GlobalVariableNode*
29 ::= Specifiers:specifiers{ s = span; } TypeExpr(moduleId, ctx):type Identifier(moduleId):id (ASSIGN Expression(moduleId, ctx):initializer)? SEMICOLON
30 {
31 s.end = span.end;
32 GlobalVariableNode* value = new GlobalVariableNode(s, *moduleId, specifiers, type, id, cu);
33 value->SetInitializer(initializer);
34 return value;
35 }
36 ;
37
38 ruleinfo
39 {
40 (GlobalVariable, "global variable")
41 }
42 }