slides

Transcription

slides
Noncanonical Parsing
Sylvain Schmitz
schmitz@i3s.unice.fr
16 mai 2006
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
1 / 22
Context-Free Grammars
The Java Programming Language
Java Declarations
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Context-Free Grammars
The Java Programming Language
Java Grammar
Gosling et al. [1996]
Example
public class Declarations {
public final static int FIELD = 10;
public static int method (int i) {
// ...
}
}
<FDecl >→ <FModS > <Type > <VDeclS > ;
<FModS >→<FModS ><FMod >| ε
<FMod >→public | final | static | transient | . . .
<Type >→ <NonVoidType >
<MHead >→<MModS ><ResType ><MDecl ><Throws >
<MModS >→<MModS ><MMod >| ε
<MMod >→public | final | static | abstract | . . .
<ResType >→ <NonVoidType >| void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
3 / 22
Bottom-Up Parsing
Nondeterminism
Example
MModS
public
final
static
int
FIELD = 10 ;
$ k public final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
Nondeterminism
Example
MModS
ε
|=
reduce
public
final
static
int
FIELD = 10 ;
$ε k public final static int FIELD = 10;$
$<MModS > k public final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
Nondeterminism
Example
MModS
ε
public
final
static
int
FIELD = 10 ;
$ <MModS > k public final static int FIELD = 10;$
|=
$ <MModS > public k final static int FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
Nondeterminism
Example
MModS
FMod
ε
public
|=
reduce
final
static
int
FIELD = 10 ;
$ <MModS > public k final static int FIELD = 10;$
$ <MModS > <FMod > k final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
Nondeterminism
Example
error!
MModS
FMod
ε
public
final
static
int
FIELD = 10 ;
$ <MModS ><FMod > k final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
LR(0) Parsing
Example
MModS
MMod
ε
public
|=
reduce
final
static
int
FIELD = 10 ;
$ <MModS > public k final static int FIELD = 10;$
$ <MModS > <MMod > k final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
LR(0) Parsing
Example
MModS
MModS
MMod
ε
public
|=
reduce
final
static
int
FIELD = 10 ;
$<MModS ><MMod > k final static int FIELD = 10;$
$<MModS > k final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
LR(0) Parsing
Example
MModS
MModS
MMod
ε
public
final
static
int
FIELD = 10 ;
$ <MModS > k final static int FIELD = 10;$
|=
$ <MModS > final k static int FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
LR(0) Parsing
Example
MModS
MModS
MMod
ε
public
|=
reduce
MMod
final
static
int
FIELD = 10 ;
$ <MModS > final k static int FIELD = 10;$
$ <MModS > <MMod > k static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
LR(0) Parsing
Example
MModS
MModS
MModS
MMod
ε
public
|=
reduce
MMod
final
static
int
FIELD = 10 ;
$<MModS ><MMod > k static int FIELD = 10;$
$<MModS > k static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
4 / 22
Bottom-Up Parsing
LR(k) Parsing
Why Determinism Matters
+ Performance
+ Safety
− Generality
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
5 / 22
Bottom-Up Parsing
LR(k) Parsing
LR(k) Parsing
Knuth [1965]
I
complete stack information
I
k symbols of lookahead
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
6 / 22
Bottom-Up Parsing
LR(k) Parsing
LR(k) Parsing
Knuth [1965]
I
complete stack information: regular language
I
k symbols of lookahead
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
6 / 22
Bottom-Up Parsing
LR(k) Parsing
LR(k) Parsing
Knuth [1965]
I
complete stack information: regular language
I
k symbols of lookahead
Example
MMod
MModS
[$]
[$ MModS]
Sylvain Schmitz (Laboratoire I3S)
[$ MModS MMod]
static
[$ MModS
Noncanonical Parsing
static ]
EJC06 (LaBRI)
6 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MMod
ε
public
|=
reduce
MMod
final
static
int
FIELD = 10 ;
[$][$ <MModS >][$ <MModS ><MMod >] k static int FIELD
[$][$ <MModS >] k static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MMod
ε
public
MMod
final
static
int
FIELD = 10 ;
[$][$ <MModS >] k static int FIELD = 10;$
|=
[$][$ <MModS >] [$ <MModS > static] k int FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MMod
ε
public
|=
reduce
MMod
MMod
final
static
int
FIELD = 10 ;
[$][$ <MModS >][$ <MModS > static] k int FIELD = 10;$
[$][$ <MModS >][$ <MModS ><MMod >] k int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MModS
MMod
ε
public
|=
reduce
MMod
MMod
final
static
int
FIELD = 10 ;
[$][$ <MModS >][$ <MModS ><MMod >] k int FIELD = 10;$
[$][$ <MModS >] k int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MModS
MMod
ε
public
MMod
MMod
final
static
int
FIELD = 10 ;
[$][$ <MModS >] k int FIELD = 10;$
|=
[$][$ <MModS >] [$ <MModS > int] k FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MModS
MMod
ε
public
|=
reduce
MMod NonVoidType
MMod
final
static
int
FIELD = 10 ;
[$][$ <MModS >]int k FIELD = 10;$
[$][$ <MModS >][$ <MModS ><NonVoidType >] k FIELD = 10
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MModS
MMod
ε
public
|=
reduce
ResType
MMod NonVoidType
MMod
final
static
int
FIELD = 10 ;
[$][$ <MModS >][$ <MModS ><NonVoidType >] k FIELD = 10
[$][$ <MModS >][$ <MModS ><ResType >] k FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MModS
MMod
ε
public
ResType
MMod NonVoidType
MMod
final
static
int FIELD = 10
;
[$] . . . k FIELD = 10;$
|=
[$] . . . [$ <MModS ><ResType > FIELD] k = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MModS
MMod
ε
public
ResType
MMod NonVoidType
MMod
final
static
int FIELD = 10
;
[$] . . . [$ <MModS ><ResType > FIELD] k = 10;$
|=
[$] . . . [$ <MModS ><ResType > FIELD =] k 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
MModS
MModS
MModS
MModS
MMod
ε
public
ResType
MMod NonVoidType
MMod
error!
final
static
int FIELD = 10
;
[$] . . . [<MModS ><ResType > FIELD =] k 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
Nondeterminism
Example
FModS
ε
|=
reduce
public
final
static
int
FIELD = 10 ;
[$]ε k public final static int FIELD = 10;$
[$][$ <FModS >] k public final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
7 / 22
Bottom-Up Parsing
LR(k) Parsing
LR(k) Parsing
I
I
complete stack information
k symbols of lookahead
Example
Choice between reductions <FModS > →ε and <MModS > →ε:
[$]εkpublic static final . . . final static int l =
[$]εkpublic static final . . . final static int l (
I
Unbounded lookahead needed for better generality
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
8 / 22
Bottom-Up Parsing
LR(k) Parsing
LR(k) Parsing
I
I
complete stack information
k symbols of lookahead
Example
Choice between reductions <FModS > →ε and <MModS > →ε:
[$]εkpublic static final . . . final static int l =
[$]εkpublic static final . . . final static int l (
I
Unbounded lookahead needed for better generality
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
8 / 22
Bottom-Up Parsing
LR(k) Parsing
LR(k) Parsing
I
I
complete stack information
k symbols of lookahead
Example
Choice between reductions <FModS > →ε and <MModS > →ε:
[$]εkpublic static final . . . final static int l =
[$]εkpublic static final . . . final static int l (
I
Unbounded lookahead needed for better generality
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
8 / 22
Noncanonical Parsing
Why Noncanonical Parsing?
Parsing a Program Source
I
Good generality
I
Determinism
I
O(n) time complexity
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
9 / 22
Noncanonical Parsing
Why Noncanonical Parsing?
Parsing a Program Source
I
Good generality
I
Determinism
I
O(n) time complexity
Noncanonical parsing
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
9 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
public
final
static
int
FIELD = 10 ;
$ k public final static int FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
public
final
static
int
FIELD = 10 ;
$ k public final static int FIELD = 10;$
|=
$ public k final static int FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
public
final
static
int
FIELD = 10 ;
$public k final static int FIELD = 10;$
|=
$public final k static int FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
public
final
static
int
FIELD = 10 ;
$public final k static int FIELD = 10;$
|=
$public final static k int FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
public
final
static
int
FIELD = 10 ;
$public final static k int FIELD = 10;$
|=
$public final static int k FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
NonVoidType
FModS
public
|=
reduce
final
static
int
FIELD = 10 ;
$public final static int k FIELD = 10;$
$public final static k <NonVoidType > FIELD = 10;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
NonVoidType
FModS
public
final
static
int
;
FIELD = 10
$public final static k <NonVoidType > FIELD = 10;$
|=
$public final static <NonVoidType > k FIELD = 10;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
NonVoidType
FModS
public
final
static
int
;
FIELD = 10
$public final static <NonVoidType > k FIELD = 10 ;$
|=
$public final static <NonVoidType > FIELD = 10 k ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
VDeclS
NonVoidType
FModS
public
|=
reduce
final
static
int
FIELD = 10
;
$public final static <NonVoidType > FIELD = 10 k ;$
$public final static <NonVoidType > k <VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Parsing Example
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
NonVoidType
FModS
public
|=
reduce
final
static
int
;
FIELD = 10
$public final static <NonVoidType > k <VDeclS > ;$
$public final static k <Type > <VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FModS
public
|=
reduce
final
static
int
FIELD = 10
;
$public final static k <Type ><VDeclS > ;$
$public final k <FMod > <Type ><VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FMod
FModS
public
|=
reduce
final
static
int
FIELD = 10
;
$public final k <FMod ><Type ><VDeclS > ;$
$public k <FMod > <FMod ><Type ><VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FMod
FModS
FMod
public
|=
reduce
final
static
int
;
FIELD = 10
$ public k <FMod ><FMod ><Type ><VDeclS > ;$
$ k <FMod > <FMod ><FMod ><Type ><VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FMod
FModS
FMod
ε
public
|=
reduce
final
static
int
FIELD = 10
;
$ ε k <FMod ><FMod ><FMod ><Type ><VDeclS > ;$
$ k <FModS > <FMod ><FMod ><FMod ><Type ><VDeclS >
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FMod
FModS
FMod
ε
public
final
static
int
FIELD = 10
;
$ k <FModS > <FMod ><FMod ><FMod ><Type ><VDeclS >
|=
$ <FModS > k <FMod ><FMod ><FMod ><Type ><VDeclS >
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FMod
FModS
FMod
ε
public
final
static
int
FIELD = 10
;
$ <FModS > k <FMod > <FMod ><FMod ><Type ><VDeclS
|=
$ <FModS > <FMod > k <FMod ><FMod ><Type ><VDeclS
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FModS
FModS
FMod
ε
public
|=
reduce
FMod
final
static
int
FIELD = 10
;
$ <FModS ><FMod > k <FMod ><FMod ><Type ><VDeclS >
$ k <FModS > <FMod ><FMod ><Type ><VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FModS
FModS
FMod
ε
public
FMod
final
static
int
;
FIELD = 10
$ k <FModS > <FMod ><FMod ><Type ><VDeclS > ;$
|=
$ <FModS > k <FMod ><FMod ><Type ><VDeclS > ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
VDeclS
FMod NonVoidType
FModS
FModS
FMod
ε
public
FMod
final
static
int
;
FIELD = 10
$ <FModS > k <FMod > <FMod ><Type ><VDeclS > ;$
|=
$ <FModS > <FMod > k <FMod ><Type ><VDeclS > ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
FModS
FModS
FModS
FMod
ε
public
|=
reduce
VDeclS
FMod NonVoidType
FMod
final
static
int
;
FIELD = 10
$ <FModS ><FMod > k <FMod ><Type ><VDeclS > ;$
$ k <FModS > <FMod ><Type ><VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
FModS
FModS
FModS
FMod
ε
public
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10
;
$ k <FModS > <FMod ><Type ><VDeclS > ;$
|=
$ <FModS > k <FMod ><Type ><VDeclS > ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
Type
FModS
FModS
FModS
FMod
ε
public
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10
;
$ <FModS > k <FMod > <Type ><VDeclS > ;$
|=
$ <FModS > <FMod > k <Type ><VDeclS > ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
FModS
FModS
FModS
FMod
ε
public
|=
reduce
Type
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10
;
$ <FModS ><FMod > k <Type ><VDeclS > ;$
$ k <FModS > <Type ><VDeclS > ;$
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
FModS
FModS
FModS
FMod
ε
public
Type
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10
;
$ k <FModS > <Type ><VDeclS > ;$
|=
$ <FModS > k <Type ><VDeclS > ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
FModS
FModS
FModS
FMod
ε
public
Type
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10
;
$ <FModS > k <Type > <VDeclS > ;$
|=
$ <FModS > <Type > k <VDeclS > ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
FModS
FModS
FModS
FMod
ε
public
Type
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10
;
$ <FModS ><Type > k <VDeclS > ;$
|=
$ <FModS ><Type > <VDeclS > k ;$
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FModS
FModS
FModS
FModS
FMod
ε
public
Type
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10 ;
$ <FModS ><Type ><VDeclS > k ; $
|=
$ <FModS ><Type ><VDeclS > ; k $
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FDecl
FModS
FModS
FModS
FModS
FMod
ε
public
|=
reduce
Type
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10 ;
$ <FModS ><Type ><VDeclS > ; k $
$ k <FDecl > $
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Parsing Example
Noncanonical Parsing
Noncanonical Parsing
Colmerauer [1970], Szymanski and Williams [1976], Tai [1979]
Example
FDecl
FModS
FModS
FModS
FModS
FMod
ε
public
Type
VDeclS
FMod NonVoidType
FMod
final
static
int
FIELD = 10 ;
$ k <FDecl > $
|=
$ <FDecl > k $
shift
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
10 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FModS
FDecl
FModS
ε
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FModS
FModS
FDecl
FMod
ε
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FModS
FModS
FMod
ε
public
FDecl
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FModS
FModS
FMod
ε
public
final
FDecl
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FModS
FModS
FMod
ε
public
final
static
transient
Sylvain Schmitz (Laboratoire I3S)
FDecl
Noncanonical Parsing
;
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FModS
FModS
FMod
ε
public
final
static
transient
Sylvain Schmitz (Laboratoire I3S)
FDecl
Noncanonical Parsing
;
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FModS
FDecl
FModS
ε
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FDecl
FModS
Type
VDeclS
ε
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FDecl
FModS
Type
VDeclS
NonVoidType
ε
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Example
FDecl
FModS
Type
VDeclS
NonVoidType
ε
int
;
transient
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Notation
<FModS > → ε
Sylvain Schmitz (Laboratoire I3S)
{public, final, static, int,
transient, <FMod >, <Type >,
<NonVoidType >}
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Comparison
<FModS > → ε
{public, final, static, int,
transient, <FMod >, <Type >,
<NonVoidType >}
<MModS > → ε
{public, final, static, int,
abstract, <MMod >, <ReturnType >,
<NonVoidType >}
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Conflicts
<FModS > → ε
{public, final, static, int,
transient, <FMod >, <Type >,
<NonVoidType >}
<MModS > → ε
{public, final, static, int,
abstract, <MMod >, <ReturnType >,
<NonVoidType >}
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical Lookaheads
Decisions
<FModS > → ε
{public, final, static, int,
transient, <FMod >, <Type >,
<NonVoidType >}
<MModS > → ε
{public, final, static, int,
abstract, <MMod >, <ReturnType >,
<NonVoidType >}
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
11 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical LALR(1)
DeRemer and Pennello [1982], Schmitz [2006]
Example
[$ MModS MMod]
MMod
MModS [$ MModS]
[$]
ε
FModS
static
FMod
[$ FModS]
static
FMod
int
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
[$ MModS
static ]
[$ FModS FMod]
[$ MModS
static ]
[$ FModS Type]
[$ FModS
static ]
EJC06 (LaBRI)
12 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical LALR(1)
DeRemer and Pennello [1982], Schmitz [2006]
Example
[$ MModS MMod]
MMod
MModS [$ MModS]
[$]
ε
FModS
static
FMod
[$ FModS]
static
FMod
int
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
[$ MModS
static ]
[$ FModS FMod]
[$ MModS
static ]
[$ FModS Type]
[$ FModS
static ]
EJC06 (LaBRI)
12 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical LALR(1)
DeRemer and Pennello [1982], Schmitz [2006]
Example
[$ MModS MMod]
MMod
MModS [$ MModS]
[$]
ε
FModS
static
FMod
[$ FModS]
static
lookback
FMod
int
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
[$ MModS
static ]
[$ FModS FMod]
[$ MModS
static ]
[$ FModS Type]
[$ FModS
static ]
EJC06 (LaBRI)
12 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical LALR(1)
DeRemer and Pennello [1982], Schmitz [2006]
Example
[$ MModS MMod]
MMod
MModS [$ MModS]
[$]
ε
FModS
static
FMod
[$ FModS]
directly
reads
static
FMod
int
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
[$ MModS
static ]
[$ FModS FMod]
[$ MModS
static ]
[$ FModS Type]
[$ FModS
static ]
EJC06 (LaBRI)
12 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Valid Covers
Schmitz [2006]
Example
FModS
public
Sylvain Schmitz (Laboratoire I3S)
final
static
Noncanonical Parsing
int
FIELD = 10 ;
EJC06 (LaBRI)
13 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Valid Covers
Schmitz [2006]
Example
FModS
FModS
FModS
FMod
ε
public
Sylvain Schmitz (Laboratoire I3S)
FMod
final
static
Noncanonical Parsing
int
FIELD = 10
;
EJC06 (LaBRI)
13 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Valid Covers
Schmitz [2006]
Example
FModS
FModS
public
Sylvain Schmitz (Laboratoire I3S)
final
static
Noncanonical Parsing
int
FIELD = 10
;
EJC06 (LaBRI)
13 / 22
Noncanonical Parsing
Noncanonical Parsers Generation
Noncanonical States
Schmitz [2006]
Example
[$ MModS MMod]
MMod
MModS [$ MModS]
[$]
static
[$static ]
FModS
[$ FModS]
static
FMod
static
[$ MModS
static ]
[$ FModS FMod]
[$ MModS
static ]
J$ staticK = {[$ static], [$ <FModS > static],
[$ <MModS > static]}
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
14 / 22
End Comments
Closing Comments
Noncanonical Parsing
I
I
I
Good generality
Determinism
O(n) time complexity
NLALR(1)
I
I
Simple & fast computations on LR(0) automaton
Other prefix equivalences possible
Improvements
Better generality: no preset lookahead length
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
15 / 22
LR(0) Construction
Valid0($ <MModS > )
MModS
MModS
MMod
Throws
int
<MModS>→ <MModS >
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
· <MMod >
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MModS
MModS
MMod
Throws
public
int
·
<MMod>→ public
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MModS
MModS
MMod
Throws
static
int
·
<MMod>→ static
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MModS
MModS
MMod
Throws
final
int
·
<MMod>→ final
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MModS
MModS
MMod
Throws
abstract
int
·
<MMod>→ abstract
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MHead
MModS
ResType
MDecl
Throws
int
<MHead>→ <MModS >
Sylvain Schmitz (Laboratoire I3S)
· <ResType ><MDecl ><Thro
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MHead
MModS
ResType
MDecl
Throws
void
int
·
<ResType>→ <NonVoidType >
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MHead
MModS
ResType
MDecl
Throws
NonVoidType
int
·
<ResType>→ void
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MHead
MModS
ResType
MDecl
Throws
NonVoidType
int
·
<NonVoidType>→ int
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
·
<MModS>→ <MModS > <MMod >
<MMod >→ public
<MMod >→ static
<MMod >→ final
<MMod >→ abstract
<MHead >→ <MModS > <ResType ><MDecl ><
<ResType >→ <NonVoidType >
<ResType >→ void
<NonVoidType >→ int
·
·
·
·
·
·
·
Sylvain Schmitz (Laboratoire I3S)
·
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > static)
MModS
MModS
MMod
Throws
static
int
·
<MMod>→static
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > <MMod >)
MModS
MModS
MMod
Throws
int
<MModS>→ <MModS ><MMod >
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
·
EJC06 (LaBRI)
16 / 22
LR(0) Construction
Valid0($ <MModS > )
MMod
MModS
[$]
[$ MModS]
Sylvain Schmitz (Laboratoire I3S)
[$ MModS MMod]
static
[$ MModS
Noncanonical Parsing
static ]
EJC06 (LaBRI)
16 / 22
Syntactic Predicates
Parr and Quong [1995]
I
User defined lookahead pattern
Example
((MMod)* ResType MDecl)?
I
Error-prone
I
Exponential time complexity
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
18 / 22
Syntactic Predicates
Parr and Quong [1995]
I
User defined lookahead pattern
Example
((MMod)* ResType MDecl)?
I
Error-prone
I
Exponential time complexity
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
18 / 22
Syntactic Predicates
Parr and Quong [1995]
I
User defined lookahead pattern
Example
((MMod)* ResType MDecl)?
I
Error-prone
I
Exponential time complexity
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
18 / 22
Syntactic Predicates
Parr and Quong [1995]
I
User defined lookahead pattern
Example
((MMod)* ResType MDecl)?
I
Error-prone
I
Exponential time complexity
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
18 / 22
LR-Regular Parsing
Baker [1981], Bermudez and Schimpf [1990], Farré and Fortes Gálvez [2001]
I
Finite State lookahead discrimination
I
O(n2 ) time complexity
I
Only considers terminal symbols
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
19 / 22
LR-Regular Parsing
Baker [1981], Bermudez and Schimpf [1990], Farré and Fortes Gálvez [2001]
I
Finite State lookahead discrimination
Example
abstract void
int
(
MModS
= , ;
FModS
IDENT
public static ...
transient
I
O(n2 ) time complexity
I
Only considers terminal symbols
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
19 / 22
LR-Regular Parsing
Baker [1981], Bermudez and Schimpf [1990], Farré and Fortes Gálvez [2001]
I
Finite State lookahead discrimination
Example
abstract void
int
(
MModS
= , ;
FModS
IDENT
public static ...
transient
I
O(n2 ) time complexity
I
Only considers terminal symbols
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
19 / 22
LR-Regular Parsing
Baker [1981], Bermudez and Schimpf [1990], Farré and Fortes Gálvez [2001]
I
Finite State lookahead discrimination
Example
abstract void
int
(
MModS
= , ;
FModS
IDENT
public static ...
transient
I
O(n2 ) time complexity
I
Only considers terminal symbols
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
19 / 22
T. P. Baker. Extending lookahead for LR parsers.
J. Comput. Syst. Sci., 22(2):243–259, 1981. doi:
10.1016/0022-0000(81)90030-1.
M. E. Bermudez and K. M. Schimpf. Practical arbitrary
lookahead LR parsing. J. Comput. Syst. Sci., 41(2):
230–250, 1990. doi: 10.1016/0022-0000(90)90037-L.
A. Colmerauer. Total precedence relations. J. ACM, 17
(1):14–30, Jan. 1970. doi: 10.1145/321556.321559.
F. DeRemer and T. Pennello. Efficient computation of
LALR(1) look-ahead sets. ACM Trans. Prog. Lang.
Syst., 4(4):615–649, 1982. doi:
10.1145/69622.357187.
J. Farré and J. Fortes Gálvez. A bounded-connect
construction for LR-regular parsers. In R. Wilhelm,
editor, CC’01, volumeNoncanonical
2027 Parsing
of Lecture Notes
in
Sylvain Schmitz (Laboratoire I3S)
EJC06 (LaBRI)
20 / 22
J. Gosling, B. Joy, and G. Steele. The JavaTM Language
Specification. Addison-Wesley Longman Publishing
Co., Inc., first edition, Aug. 1996. ISBN
0-201-63451-1. URL
http://java.sun.com/docs/books/jls/.
D. E. Knuth. On the translation of languages from left
to right. Information and Control, 8:607–639, 1965.
T. J. Parr and R. W. Quong. ANTLR: A
predicated-LL(k) parser generator. Software, Practice
and Experience, 25(7):789–810, 1995. ISSN
0038-0644. URL
http://citeseer.nj.nec.com/12770.
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
21 / 22
S. Schmitz. Noncanonical LALR(1) parsing. In Z. Dang
and O. H. Ibarra, editors, DLT’06, volume 4036 of
Lecture Notes in Computer Science, pages 95–107.
Springer, 2006.
T. G. Szymanski and J. H. Williams. Noncanonical
extensions of bottom-up parsing techniques. SIAM J.
Comput., 5(2):231–250, June 1976. URL
http://locus.siam.org/SICOMP/volume-05/
art 0205019.html.
K.-C. Tai. Noncanonical SLR(1) grammars. ACM Trans.
Prog. Lang. Syst., 1(2):295–320, 1979. ISSN
0164-0925. doi: 10.1145/357073.357083.
Sylvain Schmitz (Laboratoire I3S)
Noncanonical Parsing
EJC06 (LaBRI)
22 / 22

Similar documents