Ad/2010-08-01 Concrete Syntax for a uml action Language for Foundational uml (Alf) Second Revised Submission


Consolidated LL Grammar (informative)



Download 1.74 Mb.
Page60/62
Date28.01.2017
Size1.74 Mb.
#9041
1   ...   54   55   56   57   58   59   60   61   62

Consolidated LL Grammar
(informative)


The grammar productions presented for Alf in the main body of this document are intended to describe the lexical structure and syntax of the language in a way that is as clear as possible to a reader of the specification. However, the resulting grammar is not necessarily appropriate as the basis for automated parsing of the language. The grammar presented in this annex is equivalent to the normative grammar for Alf, but is specifically intended for use in automated parsing.

NOTE. This grammar has been implemented using JavaCC parser generator (https://javacc.dev.java.net/). The format of the lexical and syntactic productions in this annex is therefore as required for input to this tool.
    1. Lexical Analyzer


The lexical analyzer is defined as a state machine that generates a sequence of tokens that are fed to the parser. The operation of this state machine is given by the set of productions listed below. Each production has the following form:

  • A list of names of the states in which the production is active. The analyzer begins in the DEFAULT state.

  • The action of the production, which is one of the following:

  • SKIP – Any text matched by the production is skipped and not passed to the parser.

  • TOKEN – Text matched by the production forms the image of a token that is passed to the parser.

  • MORE – Text matched by the production is buffered until the next match of a production with a SKIP or TOKEN action, at which time all buffered text is either skipped or used in the construction of a token respectively.

  • A list of alternatives, each of which consists of an optional name, a regular expression and an optional target state. If the regular expression in an alternative matches the input text at the current position, then this text is consumed, the production action is carried out and the analyzer moves to the target state. If no target state is given, then the analyzer remains in the same state. If a name is given in a matching alternative and the production action is to produce a token, then the token is given that name.

Productions are checked in order, so earlier productions have precedence over later productions.

/* WHITE SPACE */


SKIP : {

" "


| "\t"

| "\f"


}
SKIP : {

"\n"


| "\r"

}
/* STATEMENT ANNOTATIONS */


TOKEN : {

: IN_STATEMENT_ANNOTATION

| : IN_IN_LINE_ANNOTATION

}
TOKEN : {

: DEFAULT

}
SKIP : {



<("//" (~["\n","\r"])*)? ("\n" | "\r" ("\n")?)> : IN_DOCUMENTATION_COMMENT

}
/* COMMENTS */


SKIP : {

<"/**" ~["/"]> : IN_DOCUMENTATION_COMMENT

}
MORE : {

"//" : IN_END_OF_LINE_COMMENT

| "/*" : IN_IN_LINE_COMMENT

}
SKIP : {

: DEFAULT

}
MORE : {



<~[]>

}
MORE : {



<~["*"]>

| "*" : IN_IN_LINE_COMMENT_STAR

}
MORE : {

<~["/"]> : IN_IN_LINE_COMMENT

}
SKIP : {



: DEFAULT

}
MORE : {



<~["*"]>

| "*" : IN_DOCUMENTATION_COMMENT_STAR

}
TOKEN : {

: DEFAULT

}
MORE : {



<~["/"]> : IN_DOCUMENTATION_COMMENT

}
/* RESERVED WORDS */


TOKEN : {

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|

|


|

|


|

|

|

|

|

|

|

|

|

|

|

|

|

}
/* NAMES */


TOKEN : {

()*>

| <#IDENTIFIER_LETTER_OR_DIGIT: | >

| <#IDENTIFIER_LETTER: ["a"-"z","A"-"Z","_"]>

| <#DIGIT: "0" | >

| <#NONZERO_DIGIT: ["1"-"9"]>

| )+ "\'">

| <#NAME_CHARACTER: ~["\'","\\"] | >

| <#ESCAPE_CHARACTER: "\\" >

| <#ESCAPED_CHARACTER: ["\'","\"","b","f","n","\\"]>

}
/* PRIMITIVE LITERALS */


TOKEN : {

| (("_")? )*>

| <#BINARY_DIGIT: ["0","1"]>

| (("_")? )*>

| <#HEX_DIGIT: | ["a"-"f","A"-"F"]>

| )+>

| <#OCTAL_DIGIT: ["0"-"7"]>

| (("_")? )*>

| )* "\"">

| <#STRING_CHARACTER: ~["\"","\\"]>

}
/* PUNCTUATION */
TOKEN : {

|

|

|

|

|

|

|

|

|

|

|

| ">

| ">

}
/* OPERATORS */
TOKEN : {

">

|

|

|

|

|

|

|

| =">

|

|

|

|

|

|

|

|

|

|

|

|

|

| >">

| >>">

|


|

| >=">

| >>=">

}



    1. Download 1.74 Mb.

      Share with your friends:
1   ...   54   55   56   57   58   59   60   61   62




The database is protected by copyright ©ininet.org 2024
send message

    Main page