Xtext的parser过程

56 篇文章 0 订阅

Basically parsing can be separated in the following phases.

  1. Lexing
  2. Parsing
  3. Linking
  4. Validation

There are four different possible cardinalities:

  1. exactly one (the default, no operator)
  2. zero or one (operator ?)
  3. zero or more (operator *)
  4. one or more (operator +)

terminal rule vs parser rules vs Data Type Rules vs Enum Rules

  1. terminal rule
    In the first stage called lexing, a sequence of characters (the text input) is transformed into a sequence of so-called tokens. In this context, a token is sort of a strongly typed part or region of the input sequence. It consists of one or more characters and is matched by a particular terminal rule or keyword and therefore represents an atomic symbol. Terminal rules are also referred to as token rules or lexer rules. There is an informal naming convention that names of terminal rules are all upper-case.
terminal ID: 
    ('^')?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*; 
  1. parser rule
    a parser rule – contrary to a terminal rule – does not produce a single atomic terminal token, but a tree of non-terminal and terminal tokens. They lead to a so-called parse tree (in Xtext it is also referred as node model). Furthermore, parser rules are handled as kind of a building plan for the creation of the EObjects that form the semantic model (the linked abstract syntax tree or AST). Due to this fact, parser rules are also called production or EObject rules.

Assignments:

DataType:
    'datatype' name = ID;

相当于 DataType dt = new DataType(); dt.name = ID;

  1. Data Type Rules
    Note that rules that do not call other parser rules and do neither contain any actions nor assignments are considered to be data type rules, and the data type EString is implied if none has been explicitly declared.

Value converters are used to transform the parsed string to the actually returned data type value.

QualifiedName returns ecore::EString: 
    ID ('.' ID)*;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值